home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / proxy11.zip / BINTREE.PRX next >
Text File  |  1991-10-14  |  506b  |  17 lines

  1. // sorting using binary search tree
  2. // insert: struct x integer -> struct
  3. // trav: struct
  4.  
  5. struct tree { value,left,right;};  // structure declaration
  6.  
  7. insert(tr,x) {if(tr=={}) return new tree(x,{},{});
  8.          if(x==tr.value) return tr;
  9.          if(x<tr.value) return new tree(tr.value,
  10.                   insert(tr.left,x),tr.right);
  11.          return new tree(tr.value,tr.left,insert(tr.right,x));};
  12.  
  13. trav(x) {if(x != {}) {print(trav(x.left));
  14.               print(x.value);
  15.               print(trav(x.right));} };
  16. end
  17.